package com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentactivityincome;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.szqhyxj.youxiangju.BasePromptFragment;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentactivityincome.fragment.ActivationrewardFragment;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentactivityincome.fragment.AllFragment;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentactivityincome.fragment.PlatformpurchaseFragment;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentactivityincome.fragment.PromotionrewardFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by leung on 2018/11/22.
 */

public class EquipmentActivityAllitemFragment extends BasePromptFragment implements EquipmentActivityAllitemFragmentContarct.View {

    @BindView(R.id.equipmentViewPager)
    ViewPager container;
    Unbinder unbinder;
    @BindView(R.id.alltitle)
    TextView alltitle;
    @BindView(R.id.allbottom)
    View allbottom;
    @BindView(R.id.allarea)
    LinearLayout allarea;
    @BindView(R.id.platformpurchasetitle)
    TextView platformpurchasetitle;
    @BindView(R.id.platformpurchasebottom)
    View platformpurchasebottom;
    @BindView(R.id.platformpurchasearea)
    LinearLayout platformpurchasearea;
    @BindView(R.id.activationrewardtitle)
    TextView activationrewardtitle;
    @BindView(R.id.activationrewardbottom)
    View activationrewardbottom;
    @BindView(R.id.activationrewardarea)
    LinearLayout activationrewardarea;
    @BindView(R.id.promotionrewardtitle)
    TextView promotionrewardtitle;
    @BindView(R.id.promotionrewardbottom)
    View promotionrewardbottom;
    @BindView(R.id.promotionrewardarea)
    LinearLayout promotionrewardarea;
    @BindColor(R.color.gray)
    int colorNormal;
    @BindColor(R.color.white)
    int colorNone;
    @BindColor(R.color.invitationColor)
    int colorSelected;
    EquipmentActivityAllitemFragmentPresentner presentner;

    public static EquipmentActivityAllitemFragment newInstance() {
        Bundle args = new Bundle();
        EquipmentActivityAllitemFragment fragment = new EquipmentActivityAllitemFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            if (presentner == null) {
                presentner = new EquipmentActivityAllitemFragmentPresentner(this);
                presentner.init();
            }
        }
    }

    private List<Fragment> fragments = new ArrayList<>();

    @Override
    protected void start() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_equipment_activity_income_allitem;
    }

    @Override
    public void showAll() {
        fragments.clear();
        fragments.add(AllFragment.newInstance());
        fragments.add(PlatformpurchaseFragment.newInstance());
        fragments.add(ActivationrewardFragment.newInstance());
        fragments.add(PromotionrewardFragment.newInstance());
        container.setAdapter(new EquipmentActivityFragmentsContainer(getChildFragmentManager(), fragments));
        container.setOffscreenPageLimit(4);
    }

    private void reset() {

        alltitle.setTextColor(colorNormal);
        platformpurchasetitle.setTextColor(colorNormal);
        activationrewardtitle.setTextColor(colorNormal);
        promotionrewardtitle.setTextColor(colorNormal);
        allbottom.setBackgroundColor(colorNone);
        platformpurchasebottom.setBackgroundColor(colorNone);
        activationrewardbottom.setBackgroundColor(colorNone);
        promotionrewardbottom.setBackgroundColor(colorNone);

    }

    @Override
    public void showAllFragment() {
        container.setCurrentItem(0, false);
        reset();
        alltitle.setTextColor(colorSelected);
        allbottom.setBackgroundColor(colorSelected);
    }

    @Override
    public void showShopFragment() {
        container.setCurrentItem(1, false);
        reset();
        platformpurchasetitle.setTextColor(colorSelected);
        platformpurchasebottom.setBackgroundColor(colorSelected);
    }

    @Override
    public void showAtivationFragment() {
        container.setCurrentItem(2, false);
        reset();
        activationrewardtitle.setTextColor(colorSelected);
        activationrewardbottom.setBackgroundColor(colorSelected);
    }

    @Override
    public void showPromotionFragment() {
        container.setCurrentItem(3, false);
        reset();
        promotionrewardtitle.setTextColor(colorSelected);
        promotionrewardbottom.setBackgroundColor(colorSelected);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.allarea, R.id.platformpurchasearea, R.id.activationrewardarea, R.id.promotionrewardarea})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.allarea:
                presentner.setAllFragment();
                break;
            case R.id.platformpurchasearea:
                presentner.setShopFragment();
                break;
            case R.id.activationrewardarea:
                presentner.setAtivationFragment();
                break;
            case R.id.promotionrewardarea:
                presentner.setPromotionFragment();
                break;
        }
    }
}
